import {
    clearLocalStorage,
    getLocalStorage,
    removeLocalStorage,
    setLocalStorage
} from './localStore'

enum Keys {
    Token = 'token',
    ExpireTime = 'expireTime',
    ChannelId = 'channelId',
    ServiceUuid = 'serviceUuid',
    UserInfo = 'userInfo'
}
//存储token到session
export const setToken = (token: string) => {
    setLocalStorage(Keys.Token, token)
}
export const getToken = () => {
    return getLocalStorage(Keys.Token)
}

export const setUserInfo = (info: string) => {
    setLocalStorage(Keys.UserInfo, info)
}
export const getUserInfo = () => {
    const info = getLocalStorage(Keys.UserInfo)
    if (info != null) {
        return JSON.parse(info)
    } else {
        return false
    }
}

//存储过期时间
export const setExpireTime = (time: number) => {
    setLocalStorage(Keys.ExpireTime, JSON.stringify(time))
}
export const getExpireTime = () => {
    return getLocalStorage(Keys.ExpireTime)
}
export const cleanSession = () => {
    removeLocalStorage(Keys.Token)
    removeLocalStorage(Keys.ExpireTime)
    removeLocalStorage(Keys.UserInfo)
    // clearLocalStorage()
}
